package com.pactera.madp.cp.service;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.cp.api.entity.WorkContactEmployeeEntity;
import com.pactera.madp.cp.api.dto.channel.ReqChannelCodeStatisticsDTO;
import com.pactera.madp.cp.api.dto.channel.ReqChannelCodeStatisticsIndexDTO;
import com.pactera.madp.cp.api.vo.channel.RespChannelCodeStatisticsVO;
import com.pactera.madp.cp.api.model.workcontact.LossContact;
import com.pactera.madp.cp.api.vo.employee.SidebarEmpTendencyVo;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface IWorkContactEmployeeService extends IService<WorkContactEmployeeEntity> {

    WorkContactEmployeeEntity getWorkContactEmployeeInfo(Integer corpId, Integer empId, Integer contactId);

    List<Integer> getBelongToEmployeeId(Integer contactId, Integer corp_id);

    List<Integer> getEmployeeToContact(Integer corpId,Integer empId);

    LossContact getEmployeeLossContactId(Integer corpId, List<Integer> empId, Integer page, Integer perPage);

    boolean updateRemarkOrDescription(Integer corpId,Integer empId,Integer contactId,String remark,String description);

    boolean insertAllContactEmployee(List<WorkContactEmployeeEntity> list,int i);

    boolean updateContactEmployee(WorkContactEmployeeEntity contactEmployeeEntity);

    boolean deleteContactEmployee(Integer corpId,Integer empId,Integer contactId);

    Integer getReal(Integer corpId);

    Integer getRecord(Integer corpId);

    List<WorkContactEmployeeEntity> getAllLossContact(String endTime,List<String> channelIds,Integer employeeId);

    List<WorkContactEmployeeEntity> getAllLossContactByEmployee(String endTime,List<String> channelIds,Integer employeeId);

    /**
     * @author: yangpengwei
     * @time: 2021/2/23 4:08 下午
     * @description 获取渠道码 - 统计分页数据
     */
    R getStatisticsOfPage(ReqChannelCodeStatisticsIndexDTO req,Page page);
    
    /**
     * @author: yangpengwei
     * @time: 2021/2/25 11:30 上午
     * @description 渠道码 - 统计折线图
     */
    RespChannelCodeStatisticsVO getStatistics(ReqChannelCodeStatisticsDTO req);

    Integer getStatistics(LocalDate date, Integer corpId);

    List<WorkContactEmployeeEntity> countWorkContactEmployeesByCorpId(Integer corpId, int code);

    List<WorkContactEmployeeEntity> countWorkContactEmployeesByCorpIdTime(Integer corpId, Date startTime, Date endTime);

    List<WorkContactEmployeeEntity> countLossWorkContactEmployeesByCorpIdTime(Integer corpId, Date startTime, Date endTime);

    WorkContactEmployeeEntity getLatestRecord(Integer corpId, Integer contactId, Integer employeeId);

    WorkContactEmployeeEntity getRelatedRecord(Integer contactId, Integer employeeId);

    WorkContactEmployeeEntity getLatest(Integer contactId, Integer employeeId);

    List<WorkContactEmployeeEntity> getLossContact( Integer corpId, Integer contactId, Integer employeeId);

    Integer getAddContact(Integer corpId, String toString);

    WorkContactEmployeeEntity getWorkContactEmployeeDel(Integer corpId, Integer contactId, Integer employeeId);

    Integer getContactCountByContactTypeAndEmployeeIds(Integer contactType, Set<Integer> employeeIds,String endTime);

    /**
     * 成员客户总数(客户去重)
     * @param employeeId  本系统成员id
     * @return  客户总数
     */
    Long contactTotal(Integer employeeId);

    /**
     * 成员今日新增客户数(客户去重)
     * @param employeeId  本系统成员id
     * @return  今日新增客户数
     */
    Long contactAdd(Integer employeeId);

    // 行内客户数统计
    Integer contactInside(String wxUserId, Integer employeeId);

    // 行内客户数统计
    Integer contactInside(String wxUserId, Integer employeeId, Date start, Date end);

    Integer getEmployeeAddCount(Integer employeeId, String beginTime, String endTime);

    Integer getEmployeeOtherCount(Integer employeeId, String beginTime, String endTime);

    List<SidebarEmpTendencyVo> contactInside(String wxUserId, Integer employeeId, Integer dateType);

    IPage<WorkContactEmployeeEntity> myPage(Integer corpId, List<String> channelIds, String startTime, String endTime, Integer empId, Page page);

    List<Map<String,Object>> getDistinctContactlistMaps(Integer corpId, Integer tenantId, DateTime dateTime);

    /**
     * 根据contactId与employeeId获取最新的记录(包含已逻辑删除的记录)
     * @param corpId
     * @param contactId
     * @param employeeId
     * @return
     */
    WorkContactEmployeeEntity getNewestRecordByContactIdAndEmployeeId(Integer corpId, Integer contactId, Integer employeeId);

}
